home *** CD-ROM | disk | FTP | other *** search
/ Double-Click / Double Click - Issue 1 (Pentrisoft).adf / Mag1 / HyperCard.doc < prev    next >
Text File  |  1996-07-17  |  3KB  |  60 lines

  1. <H2><B>Hypercard Techniques</B>
  2. <H3>
  3. I am going to show you some of the tips I used to write my top program at the moment, MacArtillery.  To get the best from this article, you should have copies of the program you can refer to see what I mean.
  4.  
  5. To start with I had to try and get gravity into the program, so the bombs would come down after I sent them up.  I did this quite easily by taking one off the initial acceleration each time, so it would slow in the air, and when the number turned negative, would come back down again!  To achieve this you need two variables, one for the position on the screen, and one for the acceleration.  This is the scripting I used to achieve it:
  6.  
  7.   subtract (acceleration) from (position)
  8.  
  9. (Subtract is used because the screen has 0 at the top so to get it going up I have to subtract.)
  10.  
  11.   subtract 1 from (acceleration)
  12.  
  13. (Slow acceleration down, then when it turns negative, bring it back to ground.)
  14.  
  15. To show the bomb, I used a large paint brush style, which clicks at the position of the bomb in black, then again in white.  This causes it to appear to move through the air when the process is repeated clicking at different co-ordinates each time.
  16.  
  17. To get an angle on the bomb, I just simply add the angle onto the x co-ordinate, so an angle of 0 didn't add any on so it went up vertically, and likewise an angle of 90 added a lot onto the x co-ordinate so it appeared to move horizontally!
  18.  
  19. Wind was basically the same as the angle, a positive wind added extra onto the x co-ordinate, and a wind against takes some off the x co-ordinate.
  20.  
  21. This is a simplified version of the actual script used:
  22.  
  23.   on mouseUp   --  When you click on the turret :
  24.  
  25.   put cd field wind into w - have wind in a variable
  26.   put cd field angle into a - have angle in a variable as well
  27.   put cd field velocity into v - have velocity in a variable
  28.  
  29.   put x co-ordinates of turret into x
  30.   put y co-ordinates of turret into y
  31.   repeat until y = ground -- repeat the following until the y  co-ordinate equals the ground.
  32.  
  33.   choose brush tool -- for the animation
  34.   choose black colour -- to show the bomb
  35.   click at x,y        }
  36.   choose white     }     Animation (Make it appear then disappear)
  37.   click at x,y        }
  38.   subtract v from y --  take velocity from y co-ordinate
  39.   subtract 1 from v --  slow velocity down (Eventually turn it negative.)
  40.  
  41.   add a to x --  add angle to x co-ordinate
  42.   add w to x -- add wind to x co-ordinate as well
  43.  
  44.   end repeat  -- continue until y goes up to peak of ark, then back down to level of targets again.
  45.  
  46. This is the basis of the program, and all the rest of it is simple extras to enhance it.  If you are interested in this sort of project, write to me and let me know of any ideas you have.  Alternatively if you don't understand this or would like further explanations on the program as a whole then again write to me.  I will try to reply to all letters sent to me.
  47.  
  48. You can write to me at:
  49.  
  50. <I> 7 Rectory Lane
  51.  Poringland
  52.  Norwich
  53.  NR14 7ST</I>
  54.  
  55. Thanks very much for reading this article and I hope you found it interesting and hope maybe it has given you some ideas of your own.
  56.  
  57. Hope to hear from you soon,
  58.  
  59. <H2><B>John Barton</B>
  60.